package cn.yx.common.core.pojo;

import cn.yx.common.core.enums.ResponseCodeEnum;
import cn.yx.common.core.pojo.base.BaseVo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>Response响应类</p>
 *
 * @param <T>
 * @author Wgssmart
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "ResponseVo", description = "响应结果")
public class ResponseVo<T> extends BaseVo {

    @ApiModelProperty(value = "响应状态码", example = "1001")
    private Integer code;

    @ApiModelProperty(value = "事务ID", example = "202210261228557895867899")
    private String transId;

    @ApiModelProperty(value = "响应消息", example = "成功")
    private String message;

    @JsonIgnore
    private String[] messageParams;

    @ApiModelProperty(value = "响应数据")
    private T data;

    private ResponseVo() {
    }

    private ResponseVo(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    private ResponseVo(Integer code, String message, String[] messageParams, T data) {
        this.code = code;
        this.message = message;
        this.messageParams = messageParams;
        this.data = data;
    }

    public static <T> ResponseVo<T> response(Integer code, String message, T data) {
        return new ResponseVo<>(code, message, data);
    }

    public static <T> ResponseVo<T> response(Integer code, String message, String[] messageParams, T data) {
        return new ResponseVo<>(code, message, messageParams, data);
    }

    public static <T> ResponseVo<T> ok(String message, T data) {
        return new ResponseVo<>(ResponseCodeEnum.OK.getCode(), message, data);
    }

    public static <T> ResponseVo<T> ok(String message, String[] messageParams, T data) {
        return new ResponseVo<>(ResponseCodeEnum.OK.getCode(), message, messageParams, data);
    }

    public static <T> ResponseVo<T> ok() {
        return new ResponseVo<>(ResponseCodeEnum.OK.getCode(), ResponseCodeEnum.OK.getMessage(), null);
    }

    public static <T> ResponseVo<T> ok(T data) {
        return new ResponseVo<>(ResponseCodeEnum.OK.getCode(), ResponseCodeEnum.OK.getMessage(), data);
    }

    public static <T> ResponseVo<T> ok(String message) {
        return new ResponseVo<>(ResponseCodeEnum.OK.getCode(), message, null);
    }

    public static <T> ResponseVo<T> fail(String message, T data) {
        return new ResponseVo<>(ResponseCodeEnum.FAIL.getCode(), message, data);
    }

    public static <T> ResponseVo<T> fail(String message, String[] messageParams, T data) {
        return new ResponseVo<>(ResponseCodeEnum.FAIL.getCode(), message, messageParams, data);
    }

    public static <T> ResponseVo<T> fail() {
        return new ResponseVo<>(ResponseCodeEnum.FAIL.getCode(), ResponseCodeEnum.FAIL.getMessage(), null);
    }

    public static <T> ResponseVo<T> fail(T data) {
        return new ResponseVo<>(ResponseCodeEnum.FAIL.getCode(), ResponseCodeEnum.FAIL.getMessage(), data);
    }

    public static <T> ResponseVo<T> fail(String message) {
        return new ResponseVo<>(ResponseCodeEnum.FAIL.getCode(), message, null);
    }

    public static <T> ResponseVo<T> dataError(String message) {
        return new ResponseVo<>(ResponseCodeEnum.DATA_ERROR.getCode(), message, null);
    }

    public static <T> ResponseVo<T> dataError(String message, String[] messageParams) {
        return new ResponseVo<>(ResponseCodeEnum.DATA_ERROR.getCode(), message, messageParams, null);
    }

    public static <T> ResponseVo<T> dataError() {
        return new ResponseVo<>(ResponseCodeEnum.DATA_ERROR.getCode(), ResponseCodeEnum.DATA_ERROR.getMessage(), null);
    }

    public static <T> ResponseVo<T> serviceError(String message) {
        return new ResponseVo<>(ResponseCodeEnum.SERVICE_ERROR.getCode(), message, null);
    }

    public static <T> ResponseVo<T> serviceError(String message, String[] messageParams) {
        return new ResponseVo<>(ResponseCodeEnum.SERVICE_ERROR.getCode(), message, messageParams, null);
    }

    public static <T> ResponseVo<T> serviceError() {
        return new ResponseVo<>(ResponseCodeEnum.SERVICE_ERROR.getCode(), ResponseCodeEnum.SERVICE_ERROR.getMessage(), null);
    }

    public static <T> ResponseVo<T> authenticationError(String message) {
        return new ResponseVo<>(ResponseCodeEnum.AUTHENTICATION_ERROR.getCode(), message, null);
    }

    public static <T> ResponseVo<T> authenticationError(String message, String[] messageParams) {
        return new ResponseVo<>(ResponseCodeEnum.AUTHENTICATION_ERROR.getCode(), message, messageParams, null);
    }

    public static <T> ResponseVo<T> authenticationError() {
        return new ResponseVo<>(ResponseCodeEnum.AUTHENTICATION_ERROR.getCode(), ResponseCodeEnum.AUTHENTICATION_ERROR.getMessage(), null);
    }

    public static <T> ResponseVo<T> authorizationError(String message) {
        return new ResponseVo<>(ResponseCodeEnum.AUTHORIZATION_ERROR.getCode(), message, null);
    }

    public static <T> ResponseVo<T> authorizationError(String message, String[] messageParams) {
        return new ResponseVo<>(ResponseCodeEnum.AUTHENTICATION_ERROR.getCode(), message, messageParams, null);
    }

    public static <T> ResponseVo<T> authorizationError() {
        return new ResponseVo<>(ResponseCodeEnum.AUTHENTICATION_ERROR.getCode(), ResponseCodeEnum.AUTHORIZATION_ERROR.getMessage(), null);
    }

}
